<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Goods extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'goods';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text'
    ];

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getRecommendList()
    {
        return ['1' => __('Recommend 1'), '2' => __('Recommend 2')];
    }
    public function getIsShipList()
    {
        return ['0' => __('Is_ship 0'), '1' => __('Is_ship 1')];
    }

    public function getRecommendTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['recommend']) ? $data['recommend'] : '');
        $list = $this->getRecommendList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function category3()
    {
        return $this->belongsTo('GoodsCategory', 'category3_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function category2()
    {
        return $this->belongsTo('GoodsCategory', 'category2_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function category1()
    {
        return $this->belongsTo('GoodsCategory', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function brand()
    {
        return $this->belongsTo('Brand', 'brand_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
